package cn.itlaobing.train.dao;

import cn.itlaobing.train.entity.TrainEntity;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * Created by Administrator on 2017/11/10.
 */
public class TrainDao extends BaseDao {
    public float queryBytrainNumAndTrainStation(String trainNum,String beginStation,String endStation)throws SQLException {
        QueryRunner qr=new QueryRunner(getDataSource());
        String sql="select * from station where trainNum=? and station=? ";
        BeanHandler<TrainEntity> beanHandler=new BeanHandler<TrainEntity>(TrainEntity.class);
        TrainEntity trainEntity1=qr.query(sql,beanHandler,trainNum,beginStation);
        sql="select * from station where trainNum=? and station=?";
        TrainEntity trainEntity2=qr.query(sql,beanHandler,trainNum,endStation);
        System.out.print(trainEntity1.getSitePrice());
        System.out.print(trainEntity2.getSitePrice());

        return trainEntity2.getSitePrice()-trainEntity1.getSitePrice();
    }
}
